Skip to content

Fix support for literal mappings.#624

Merged
gouttegd merged 1 commit intomapping-commons:masterfrom
gouttegd:fix-literal-mapping-check
Oct 6, 2025
Merged

Fix support for literal mappings.#624
gouttegd merged 1 commit intomapping-commons:masterfrom
gouttegd:fix-literal-mapping-check

Conversation

@gouttegd
Copy link
Contributor

@gouttegd gouttegd commented Oct 4, 2025

Since the LinkML-generated Mapping class does not, in itself, validates the post-conditions specified in the schema, it cannot validate that a Mapping object is created with either a subject_id or (if subject_type is rdfs literal) a subject_label (likewise for the object side).

Instead, that validation is performed by custom code executed as part of the parser (after the parsing proper has been done, but before return a MappingSetDataFrame to the caller).

However, the present validation is bogus because the check on the value of subject_type and object_type is trying to compare the value of the slot to a literal string, instead of a EntityTypeEnum object. We fix that comparison here.

Since the LinkML-generated Mapping class does not, in itself, validates
the post-conditions specified in the schema, it cannot validate that a
Mapping object is created with either a subject_id or (if subject_type
is `rdfs literal`) a subject_label (likewise for the object side).

Instead, that validation is performed by custom code executed as part of
the parsing code.

However, the present validation is bogus because the check on the value
of `subject_type` and `object_type` is trying to compare the value of
the slot to a literal string, instead of a EntityTypeEnum object. We fix
that comparison here.
@gouttegd gouttegd requested a review from matentzn October 4, 2025 16:10
try:
m = Mapping(**mdict)
if m.subject_type == "rdfs literal":
if m.subject_type == EntityTypeEnum(EntityTypeEnum["rdfs literal"]):
Copy link
Contributor Author

@gouttegd gouttegd Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: As strange as it may look like, this is the normal way of comparing LinkML-defined enum values.

A comparison like this:

m.subject_type == EntityTypeEnum["rdfs literal"]

would not work because EntityTypeEnum["rdfs literal"] is not the actual enum value, it is the LinkML PermissibleValue object that represents the enum value (that’s not the same thing!). We must give that value to the EntityTypeEnum constructor to obtain an actual enum value that we can compare to the value of the slot.

See here for details, and here for a request for an easier way of working with LinkML enums.

(Of course in our case this is make even weirder by the fact that our enum values contain space characters, and LinkML does not allow to distinguish between the actual value to be used in data and the symbol used in Python code.)

@gouttegd gouttegd self-assigned this Oct 4, 2025
Copy link
Collaborator

@matentzn matentzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated, thank you!

@gouttegd gouttegd merged commit 0c05ff1 into mapping-commons:master Oct 6, 2025
6 checks passed
@gouttegd gouttegd deleted the fix-literal-mapping-check branch October 6, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants